<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link type="text/css" rel="stylesheet" href="../css/main.css"/>
<script type="text/javascript" src="../js/jquery-1.7.1.js"></script>
</head>
<body>

<table class="tb_main">
	<tr class="tb_title"><th colspan="10">玩家活动列表</th></tr>
	<tr>
		<td width="5%">游戏平台</td>
		<td width="5%">服务器</td>
		<td width="5%">活动id</td>
		<td width="5%">活动名称</td>
		<td width="5%">活动内容</td>
		<td width="5%">活动开始时间</td>
		<td width="5%">活动领奖时间</td>
		<td width="5%">活动到期时间</td>
		<!--
		<td width="20%">活动规则设置</td>
		<td width="20%">活动奖励物品</td>
		-->
		<td width="10%" >操作</td>
	</tr>
	<{foreach from=$activitys key=key item=value}>
	<tr>
		<td><{$value.platform_id}></td>
		<td><{$value.server_id}></td>
		<td><{$value.act_id}></td>
		<td><{$value.act_name}></td>
		<td><{$value.act_content}></td>
		<td><{$value.start_date}></td>
		<td><{$value.award_date}></td>
		<td><{$value.finish_date}></td>
		<!--
		<td><{$value.act_info}></td>
		<td><{$value.actgift_info}></td>
		-->
		<td>
			<{if $value.status == 0}>
			<img  alt="open" src="../images/start.jpg" class="open-btn">
			<img alt="modify" src="../images/modify.jpg"  onclick="javascript:window.location.href='activity_manage.php?act=modify&actId=<{$value.act_id}>'"/>
			<img alt="del" src="../images/delete.jpg" onclick="deletAct(<{$value.act_id}>);">
			<{else}>	
			<img alt="stop" src="../images/stop.jpg"  class="stop-btn"">
			<{/if}>
		</td>
	</tr>
	<{/foreach}>
</table>

<div class="pages"><{$page}></div>

<script type="text/javascript">

$(document).ready(function(){
	$(".open-btn").click(function(){
			
			if(!confirm('确定要开启该活动？'))
			{
				return false;
			}

			if(confirm('是否需要删除当前活动领取过的奖励？'))
			{
				var action = 0;			//0删除
			}
			else
			{
				var action = 1;			//不删除
			}

			var actid = $(this).parents().find("td").eq(2).text();
			var tr = $(this).parents("tr");
			var td= $(this).parent();
			
			$.getJSON(
					'activity_list.php?act=open',
					{actid:actid,action:action},
					function(callback){
						var info = '<table class="tb_main"><tr class="tb_title"><td colspan="4">操作返回信息</td></tr><tr>';
						$.each(callback,function(i,msg){
							if(msg.status == 1)
							{
								info = info + '<td>' + msg.server + '</td><td>活动发送成功!</td>';
								if((i+1)%2 == 0)
								{
									info = info + '</tr><tr>';
								}
							}
							else
							{
								info = info + '<td>' + msg.server + '</td><td id="error' + msg.serverId + '">活动发送<font color="red">失败!</font></td>';
								if((i+1)%2 == 0)
								{
									info = info + '</tr><tr>';
								}
							}
						});
						info = info + '<tr><td colspan="4"><button type="button" onclick="javascript:window.location.reload();">确定</button></td></tr></table>';
						tr.after('<tr><td colspan="9">'+info+'</td></tr>');
						var str = '<img alt="stop" src="../images/stop.jpg" class="stop-btn"/>';
						td.empty().html(str);
					} 
				);
		});

 $(".stop-btn").click(function(){
		 if(!confirm('确定要停止该活动？'))
		{
			return false;
		}
		var actid = $(this).parents().find("td").eq(2).text();
		var tr = $(this).parents("tr");
		var td= $(this).parent();

		$.getJSON(
				'activity_list.php?act=stop',
				{actid:actid},
				function(callback){
					var info = '<table class="tb_main"><tr class="tb_title"><td colspan="4">操作返回信息</td></tr><tr>';
					$.each(callback,function(i,msg){
						if(msg.status == 1)
						{
							info = info + '<td>' + msg.server + '</td><td>活动停止成功!</td>';
							if((i+1)%2 == 0)
							{
								info = info + '</tr><tr>';
							}
						}
						else
						{
							info = info + '<td>' + msg.server + '</td><td id="error' + msg.serverId + '">活动停止<font color="red">失败!</font></td>';
							if((i+1)%2 == 0)
							{
								info = info + '</tr><tr>';
							}
						}
					});
					info = info +  '<tr><td colspan="4"><button type="button" onclick="javascript:window.location.reload();">确定</button></td></tr></table>';
					tr.after('<tr><td colspan="9">'+info+'</td></tr>');
					var str = '<img  alt="open" src="../images/start.jpg" class="open-btn">'+
								   '<img alt="modify" src="../images/modify.jpg"  onclick="javascript:window.location.href='+
					   				"'activity_manage.php?act=modify&actId="+actid+"'"+'"/>'+
									'<img alt="del" src="../images/delete.jpg" onclick="deletAct('+actid+');">';
					td.empty().html(str);
				} 
			);

		
	 });
	
});


//删除活动
function deletAct(actId)
{
	if(!confirm('确定要删除？'))
	{
		return false;
	}
		
	var actid = actId;
	$.getJSON(	
			'activity_list.php?act=delete',
			{actid:actid},
			function(callback){
				if(callback == 1)
				{
					alert('deleted');
					 window.location.reload();
					return true;
				}
				else
				{
					alert('failed');
					return false;
				}
			} 
		);
}

$(document).ready(function(){
	$('.tb_main tr:odd').addClass('colorodd');
	$('.tb_main tr:even').addClass('coloreven');
	$(".tb_main tr").hover(function(){$(this).addClass("colorhover")},function(){$(this).removeClass("colorhover")});
});

</script>

</body>
</html>